<?php
class ActiveRecord extends CActiveRecord
{
	public function checkRange($from, $to, $field, $criteria = false)
	{
		$int_from = strtotime($this->$from);
		$int_to   = strtotime($this->$to);

		if(($int_from > 0 && $int_to == 0) || 
			($int_from == 0 && $int_to > 0) || 
			($int_from > 0 && $int_to > 0 && $int_from >= strtotime($this->$to . ' 23:59:59')))
		{
			$this->addError($field,Yii::t('admin.page', 'Date range is incorrect.'));
		}

		if($criteria && $int_from > 0 && $int_to > 0)
			$criteria->addBetweenCondition($field, $int_from, strtotime($this->$to . ' 23:59:59'));
	}
}